﻿<!--
// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
-->

<!-- 

    Important sample note:
    The purpose of this example is to demonstrate a ComboBox-like template and 
    set of properties for AutoCompleteBox that provides some level of "editable 
    ComboBox" support.

    This is not intended to be a drop-in replacement for a WPF editable combo 
    box.

    -->

<UserControl x:Class="System.Windows.Controls.Samples.AutoCompleteComboBox"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:input="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input">
    <StackPanel>
        <StackPanel.Resources>

            <!-- Custom toggle button template -->
            <Style x:Name="ComboToggleButton" TargetType="ToggleButton">
                <Setter Property="Foreground" Value="#FF333333"/>
                <Setter Property="IsTabStop" Value="False" />
                <Setter Property="Background" Value="#FF1F3B53"/>
                <Setter Property="Padding" Value="0"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="ToggleButton">
                            <Grid>
                                <Rectangle Fill="Transparent" />
                                <ContentPresenter
                            x:Name="contentPresenter"
                            Content="{TemplateBinding Content}"
                            ContentTemplate="{TemplateBinding ContentTemplate}"
                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                            Margin="{TemplateBinding Padding}"/>
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <!-- Custom control template used for the IntelliSense sample -->
            <Style x:Key="AutoCompleteComboBoxStyle" TargetType="input:AutoCompleteBox">

                <!-- ComboBox should not perform text completion by default -->
                <Setter Property="IsTextCompletionEnabled" Value="False" />

                <!-- The minimum prefix length should be 0 for combo box scenarios -->
                <Setter Property="MinimumPrefixLength" Value="0" />

                <!-- Regular template values -->
                <Setter Property="Background" Value="#FF1F3B53"/>
                <Setter Property="IsTabStop" Value="False" />
                <Setter Property="HorizontalContentAlignment" Value="Left"/>
                <Setter Property="BorderBrush">
                    <Setter.Value>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FFA3AEB9" Offset="0"/>
                            <GradientStop Color="#FF8399A9" Offset="0.375"/>
                            <GradientStop Color="#FF718597" Offset="0.375"/>
                            <GradientStop Color="#FF617584" Offset="1"/>
                        </LinearGradientBrush>
                    </Setter.Value>
                </Setter>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="input:AutoCompleteBox">
                            <Grid Margin="{TemplateBinding Padding}">
                                <TextBox IsTabStop="True" x:Name="Text" Style="{TemplateBinding TextBoxStyle}" Margin="0" />
                                <ToggleButton 
                                HorizontalAlignment="Right"
                                VerticalAlignment="Center"
                                Style="{StaticResource ComboToggleButton}"
                                Margin="0"
                                HorizontalContentAlignment="Center" 
                                Background="{TemplateBinding Background}" 
                                BorderThickness="0" 
                                Height="16" Width="16"
                                Click="DropDownToggle_Click">
                                    <ToggleButton.Content>
                                        <Path x:Name="BtnArrow" Height="4" Width="8" Stretch="Uniform" Data="F1 M 301.14,-189.041L 311.57,-189.041L 306.355,-182.942L 301.14,-189.041 Z " 
                                          Margin="0,0,6,0" HorizontalAlignment="Right">
                                            <Path.Fill>
                                                <SolidColorBrush x:Name="BtnArrowColor" Color="#FF333333"/>
                                            </Path.Fill>
                                        </Path>
                                    </ToggleButton.Content>
                                </ToggleButton>
                                <Popup x:Name="Popup">
                                    <Border x:Name="PopupBorder" HorizontalAlignment="Stretch" Opacity="1.0" BorderThickness="0" CornerRadius="3">
                                        <Border.RenderTransform>
                                            <TranslateTransform X="2" Y="2" />
                                        </Border.RenderTransform>
                                        <Border.Background>
                                            <SolidColorBrush Color="#11000000" />
                                        </Border.Background>
                                        <Border HorizontalAlignment="Stretch" BorderThickness="0" CornerRadius="3">
                                            <Border.Background>
                                                <SolidColorBrush Color="#11000000" />
                                            </Border.Background>
                                            <Border.RenderTransform>
                                                <TransformGroup>
                                                    <ScaleTransform />
                                                    <SkewTransform />
                                                    <RotateTransform />
                                                    <TranslateTransform X="-1" Y="-1" />
                                                </TransformGroup>
                                            </Border.RenderTransform>
                                            <Border HorizontalAlignment="Stretch" Opacity="1.0" Padding="2" BorderThickness="2" BorderBrush="{TemplateBinding BorderBrush}" CornerRadius="3">
                                                <Border.RenderTransform>
                                                    <TransformGroup>
                                                        <ScaleTransform />
                                                        <SkewTransform />
                                                        <RotateTransform />
                                                        <TranslateTransform X="-2" Y="-2" />
                                                    </TransformGroup>
                                                </Border.RenderTransform>
                                                <Border.Background>
                                                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                                        <GradientStop Color="#FFDDDDDD" Offset="0"/>
                                                        <GradientStop Color="#AADDDDDD" Offset="1"/>
                                                    </LinearGradientBrush>
                                                </Border.Background>
                                                <ListBox x:Name="Selector" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" ItemTemplate="{TemplateBinding ItemTemplate}" />
                                            </Border>
                                        </Border>
                                    </Border>
                                </Popup>
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <!-- DataTemplate for IntelliSense entries -->
            <DataTemplate x:Key="IntelliSenseDataTemplate">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="16" />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <ContentPresenter Content="{Binding Icon}" />
                    <TextBlock Foreground="{Binding ForegroundColor}" Padding="6, 0, 0, 0" Text="{Binding Name}" Grid.Column="1" />
                </Grid>
            </DataTemplate>

            <!-- DataTemplate for controls -->
            <DataTemplate x:Key="ControlDictionaryDataTemplate">
                <Grid>
                    <TextBlock Text="{Binding Key}" />
                </Grid>
            </DataTemplate>

        </StackPanel.Resources>

        <!-- IntelliSense-style AutoCompleteBox -->
        <ContentControl Content="API Explorer" Style="{StaticResource Header}" />
        

        <TextBlock Style="{StaticResource Information}">
            This AutoCompleteBox control has been styled to look and 
            act much like the standard editable ComboBox control. It also 
            provides suggestions using the Contains FilterMode.
        </TextBlock>

        <Grid Margin="4">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="130" />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <TextBlock Width="130" Margin="5">Type:</TextBlock>
            <input:AutoCompleteBox
                x:Name="ControlPicker"
                Style="{StaticResource AutoCompleteComboBoxStyle}"
                ItemTemplate="{StaticResource ControlDictionaryDataTemplate}"
                Width="400" 
                HorizontalAlignment="Left"
                MinimumPopulateDelay="0"
                MinimumPrefixLength="0"
                IsTextCompletionEnabled="False"
                FilterMode="None"
                Opacity="0.75"
                Grid.Column="1"
            />
        </Grid>
        
        <Grid Margin="4">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="130" />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <TextBlock Width="130" Margin="5">API ComboBox:</TextBlock>
            <input:AutoCompleteBox 
                x:Name="ControlApi" 
                ItemTemplate="{StaticResource IntelliSenseDataTemplate}"
                Style="{StaticResource AutoCompleteComboBoxStyle}"
                Width="400"
                IsTextCompletionEnabled="False"
                MinimumPrefixLength="0"
                MinimumPopulateDelay="200"
                IsEnabled="False"
                HorizontalAlignment="Left"
                Grid.Column="1"
                Opacity="0.75"
                />
        </Grid>

        <Grid Margin="4">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="130" />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <TextBlock Width="130" Margin="5">Selected Item:</TextBlock>
            <StackPanel Orientation="Horizontal" Grid.Column="1">
                <ContentPresenter MaxHeight="16" MaxWidth="16" x:Name="IntelliSenseIcon" Margin="5" />
                <TextBlock Margin="5" FontSize="18" x:Name="SelectedInformation" />
            </StackPanel>
        </Grid>

        <src:SourceViewer xmlns:src="clr-namespace:System.Windows.Controls.Samples;assembly=System.Windows.Controls.Samples.Common" xmlns:sys="clr-namespace:System;assembly=mscorlib">
  <src:SourceFile Path="AutoCompleteComboBox.xaml">
    <src:SourceFile.Source>
      <sys:String>&lt;!--
// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
--&gt;

&lt;!-- 

    Important sample note:
    The purpose of this example is to demonstrate a ComboBox-like template and 
    set of properties for AutoCompleteBox that provides some level of "editable 
    ComboBox" support.

    This is not intended to be a drop-in replacement for a WPF editable combo 
    box.

    --&gt;

&lt;UserControl x:Class="System.Windows.Controls.Samples.AutoCompleteComboBox"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:input="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input"&gt;
    &lt;StackPanel&gt;
        &lt;StackPanel.Resources&gt;

            &lt;!-- Custom toggle button template --&gt;
            &lt;Style x:Name="ComboToggleButton" TargetType="ToggleButton"&gt;
                &lt;Setter Property="Foreground" Value="#FF333333"/&gt;
                &lt;Setter Property="IsTabStop" Value="False" /&gt;
                &lt;Setter Property="Background" Value="#FF1F3B53"/&gt;
                &lt;Setter Property="Padding" Value="0"/&gt;
                &lt;Setter Property="Template"&gt;
                    &lt;Setter.Value&gt;
                        &lt;ControlTemplate TargetType="ToggleButton"&gt;
                            &lt;Grid&gt;
                                &lt;Rectangle Fill="Transparent" /&gt;
                                &lt;ContentPresenter
                            x:Name="contentPresenter"
                            Content="{TemplateBinding Content}"
                            ContentTemplate="{TemplateBinding ContentTemplate}"
                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                            Margin="{TemplateBinding Padding}"/&gt;
                            &lt;/Grid&gt;
                        &lt;/ControlTemplate&gt;
                    &lt;/Setter.Value&gt;
                &lt;/Setter&gt;
            &lt;/Style&gt;

            &lt;!-- Custom control template used for the IntelliSense sample --&gt;
            &lt;Style x:Key="AutoCompleteComboBoxStyle" TargetType="input:AutoCompleteBox"&gt;

                &lt;!-- ComboBox should not perform text completion by default --&gt;
                &lt;Setter Property="IsTextCompletionEnabled" Value="False" /&gt;

                &lt;!-- The minimum prefix length should be 0 for combo box scenarios --&gt;
                &lt;Setter Property="MinimumPrefixLength" Value="0" /&gt;

                &lt;!-- Regular template values --&gt;
                &lt;Setter Property="Background" Value="#FF1F3B53"/&gt;
                &lt;Setter Property="IsTabStop" Value="False" /&gt;
                &lt;Setter Property="HorizontalContentAlignment" Value="Left"/&gt;
                &lt;Setter Property="BorderBrush"&gt;
                    &lt;Setter.Value&gt;
                        &lt;LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"&gt;
                            &lt;GradientStop Color="#FFA3AEB9" Offset="0"/&gt;
                            &lt;GradientStop Color="#FF8399A9" Offset="0.375"/&gt;
                            &lt;GradientStop Color="#FF718597" Offset="0.375"/&gt;
                            &lt;GradientStop Color="#FF617584" Offset="1"/&gt;
                        &lt;/LinearGradientBrush&gt;
                    &lt;/Setter.Value&gt;
                &lt;/Setter&gt;
                &lt;Setter Property="Template"&gt;
                    &lt;Setter.Value&gt;
                        &lt;ControlTemplate TargetType="input:AutoCompleteBox"&gt;
                            &lt;Grid Margin="{TemplateBinding Padding}"&gt;
                                &lt;TextBox IsTabStop="True" x:Name="Text" Style="{TemplateBinding TextBoxStyle}" Margin="0" /&gt;
                                &lt;ToggleButton 
                                HorizontalAlignment="Right"
                                VerticalAlignment="Center"
                                Style="{StaticResource ComboToggleButton}"
                                Margin="0"
                                HorizontalContentAlignment="Center" 
                                Background="{TemplateBinding Background}" 
                                BorderThickness="0" 
                                Height="16" Width="16"
                                Click="DropDownToggle_Click"&gt;
                                    &lt;ToggleButton.Content&gt;
                                        &lt;Path x:Name="BtnArrow" Height="4" Width="8" Stretch="Uniform" Data="F1 M 301.14,-189.041L 311.57,-189.041L 306.355,-182.942L 301.14,-189.041 Z " 
                                          Margin="0,0,6,0" HorizontalAlignment="Right"&gt;
                                            &lt;Path.Fill&gt;
                                                &lt;SolidColorBrush x:Name="BtnArrowColor" Color="#FF333333"/&gt;
                                            &lt;/Path.Fill&gt;
                                        &lt;/Path&gt;
                                    &lt;/ToggleButton.Content&gt;
                                &lt;/ToggleButton&gt;
                                &lt;Popup x:Name="Popup"&gt;
                                    &lt;Border x:Name="PopupBorder" HorizontalAlignment="Stretch" Opacity="1.0" BorderThickness="0" CornerRadius="3"&gt;
                                        &lt;Border.RenderTransform&gt;
                                            &lt;TranslateTransform X="2" Y="2" /&gt;
                                        &lt;/Border.RenderTransform&gt;
                                        &lt;Border.Background&gt;
                                            &lt;SolidColorBrush Color="#11000000" /&gt;
                                        &lt;/Border.Background&gt;
                                        &lt;Border HorizontalAlignment="Stretch" BorderThickness="0" CornerRadius="3"&gt;
                                            &lt;Border.Background&gt;
                                                &lt;SolidColorBrush Color="#11000000" /&gt;
                                            &lt;/Border.Background&gt;
                                            &lt;Border.RenderTransform&gt;
                                                &lt;TransformGroup&gt;
                                                    &lt;ScaleTransform /&gt;
                                                    &lt;SkewTransform /&gt;
                                                    &lt;RotateTransform /&gt;
                                                    &lt;TranslateTransform X="-1" Y="-1" /&gt;
                                                &lt;/TransformGroup&gt;
                                            &lt;/Border.RenderTransform&gt;
                                            &lt;Border HorizontalAlignment="Stretch" Opacity="1.0" Padding="2" BorderThickness="2" BorderBrush="{TemplateBinding BorderBrush}" CornerRadius="3"&gt;
                                                &lt;Border.RenderTransform&gt;
                                                    &lt;TransformGroup&gt;
                                                        &lt;ScaleTransform /&gt;
                                                        &lt;SkewTransform /&gt;
                                                        &lt;RotateTransform /&gt;
                                                        &lt;TranslateTransform X="-2" Y="-2" /&gt;
                                                    &lt;/TransformGroup&gt;
                                                &lt;/Border.RenderTransform&gt;
                                                &lt;Border.Background&gt;
                                                    &lt;LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"&gt;
                                                        &lt;GradientStop Color="#FFDDDDDD" Offset="0"/&gt;
                                                        &lt;GradientStop Color="#AADDDDDD" Offset="1"/&gt;
                                                    &lt;/LinearGradientBrush&gt;
                                                &lt;/Border.Background&gt;
                                                &lt;ListBox x:Name="Selector" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" ItemTemplate="{TemplateBinding ItemTemplate}" /&gt;
                                            &lt;/Border&gt;
                                        &lt;/Border&gt;
                                    &lt;/Border&gt;
                                &lt;/Popup&gt;
                            &lt;/Grid&gt;
                        &lt;/ControlTemplate&gt;
                    &lt;/Setter.Value&gt;
                &lt;/Setter&gt;
            &lt;/Style&gt;

            &lt;!-- DataTemplate for IntelliSense entries --&gt;
            &lt;DataTemplate x:Key="IntelliSenseDataTemplate"&gt;
                &lt;Grid&gt;
                    &lt;Grid.ColumnDefinitions&gt;
                        &lt;ColumnDefinition Width="16" /&gt;
                        &lt;ColumnDefinition /&gt;
                    &lt;/Grid.ColumnDefinitions&gt;
                    &lt;ContentPresenter Content="{Binding Icon}" /&gt;
                    &lt;TextBlock Foreground="{Binding ForegroundColor}" Padding="6, 0, 0, 0" Text="{Binding Name}" Grid.Column="1" /&gt;
                &lt;/Grid&gt;
            &lt;/DataTemplate&gt;

            &lt;!-- DataTemplate for controls --&gt;
            &lt;DataTemplate x:Key="ControlDictionaryDataTemplate"&gt;
                &lt;Grid&gt;
                    &lt;TextBlock Text="{Binding Key}" /&gt;
                &lt;/Grid&gt;
            &lt;/DataTemplate&gt;

        &lt;/StackPanel.Resources&gt;

        &lt;!-- IntelliSense-style AutoCompleteBox --&gt;
        &lt;ContentControl Content="API Explorer" Style="{StaticResource Header}" /&gt;
        

        &lt;TextBlock Style="{StaticResource Information}"&gt;
            This AutoCompleteBox control has been styled to look and 
            act much like the standard editable ComboBox control. It also 
            provides suggestions using the Contains FilterMode.
        &lt;/TextBlock&gt;

        &lt;Grid Margin="4"&gt;
            &lt;Grid.ColumnDefinitions&gt;
                &lt;ColumnDefinition Width="130" /&gt;
                &lt;ColumnDefinition /&gt;
            &lt;/Grid.ColumnDefinitions&gt;
            &lt;TextBlock Width="130" Margin="5"&gt;Type:&lt;/TextBlock&gt;
            &lt;input:AutoCompleteBox
                x:Name="ControlPicker"
                Style="{StaticResource AutoCompleteComboBoxStyle}"
                ItemTemplate="{StaticResource ControlDictionaryDataTemplate}"
                Width="400" 
                HorizontalAlignment="Left"
                MinimumPopulateDelay="0"
                MinimumPrefixLength="0"
                IsTextCompletionEnabled="False"
                FilterMode="None"
                Opacity="0.75"
                Grid.Column="1"
            /&gt;
        &lt;/Grid&gt;
        
        &lt;Grid Margin="4"&gt;
            &lt;Grid.ColumnDefinitions&gt;
                &lt;ColumnDefinition Width="130" /&gt;
                &lt;ColumnDefinition /&gt;
            &lt;/Grid.ColumnDefinitions&gt;
            &lt;TextBlock Width="130" Margin="5"&gt;API ComboBox:&lt;/TextBlock&gt;
            &lt;input:AutoCompleteBox 
                x:Name="ControlApi" 
                ItemTemplate="{StaticResource IntelliSenseDataTemplate}"
                Style="{StaticResource AutoCompleteComboBoxStyle}"
                Width="400"
                IsTextCompletionEnabled="False"
                MinimumPrefixLength="0"
                MinimumPopulateDelay="200"
                IsEnabled="False"
                HorizontalAlignment="Left"
                Grid.Column="1"
                Opacity="0.75"
                /&gt;
        &lt;/Grid&gt;

        &lt;Grid Margin="4"&gt;
            &lt;Grid.ColumnDefinitions&gt;
                &lt;ColumnDefinition Width="130" /&gt;
                &lt;ColumnDefinition /&gt;
            &lt;/Grid.ColumnDefinitions&gt;
            &lt;TextBlock Width="130" Margin="5"&gt;Selected Item:&lt;/TextBlock&gt;
            &lt;StackPanel Orientation="Horizontal" Grid.Column="1"&gt;
                &lt;ContentPresenter MaxHeight="16" MaxWidth="16" x:Name="IntelliSenseIcon" Margin="5" /&gt;
                &lt;TextBlock Margin="5" FontSize="18" x:Name="SelectedInformation" /&gt;
            &lt;/StackPanel&gt;
        &lt;/Grid&gt;

    &lt;/StackPanel&gt;
&lt;/UserControl&gt;
</sys:String>
    </src:SourceFile.Source>
  </src:SourceFile>
  <src:SourceFile Path="AutoCompleteComboBox.xaml.cs">
    <src:SourceFile.Source>
      <sys:String>// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Reflection;
using System.Windows.Controls.DataVisualization.Charting;
using System.Windows.Data;
using System.Windows.Media;

[assembly: SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields", Scope = "member", Target = "System.Windows.Controls.Samples.AutoCompleteComboBox.#ComboToggleButton", Justification = "Artifact of using a name inside the custom control template.")]

namespace System.Windows.Controls.Samples
{
    /// &lt;summary&gt;
    /// The AutoCompleteComboBox sample page shows the use of custom data
    /// objects, data templates, and a completely custom control template that 
    /// acts and looks much like a ComboBox with AutoCompleteBox capabilities.
    /// &lt;/summary&gt;
    [Sample("(3)Styling", DifficultyLevel.Intermediate)]
    [Category("AutoCompleteBox")]
    public partial class AutoCompleteComboBox : UserControl
    {
        /// &lt;summary&gt;
        /// Initializes a new instance of the AutoCompleteComboBox class.
        /// &lt;/summary&gt;
        public AutoCompleteComboBox()
        {
            InitializeComponent();
            Loaded += OnLoaded;
        }

        /// &lt;summary&gt;
        /// Handle the Loaded event of the page.
        /// &lt;/summary&gt;
        /// &lt;param name="sender"&gt;The source object.&lt;/param&gt;
        /// &lt;param name="rea"&gt;The event arguments.&lt;/param&gt;
        private void OnLoaded(object sender, RoutedEventArgs rea)
        {
            ControlApi.ItemFilter = (prefix, item) =&gt;
            {
                if (string.IsNullOrEmpty(prefix))
                { 
                    return true; 
                }
                MemberInfoData pme = item as MemberInfoData;
                if (pme == null)
                {
                    return false; 
                }
                return (pme.Name.ToUpper(CultureInfo.InvariantCulture).Contains(prefix.ToUpper(CultureInfo.InvariantCulture)));
            };

            // Reflect and load data
            ControlApi.ItemsSource = MemberInfoData.GetSetForType(typeof(AutoCompleteBox));
            ControlPicker.ItemsSource = InitializeTypeList();

            // Set the changed handlers
            ControlApi.SelectionChanged += OnApiChanged;
            ControlPicker.SelectionChanged += OnPickerChanged;
            
            // Setup the dictionary converter
            ControlPicker.ValueMemberBinding = new Binding
            {
                Converter = new DictionaryKeyValueConverter&lt;string, Type&gt;()
            };
        }

        /// &lt;summary&gt;
        /// Update the API system.
        /// &lt;/summary&gt;
        /// &lt;param name="sender"&gt;The source object.&lt;/param&gt;
        /// &lt;param name="e"&gt;The selection changed event data.&lt;/param&gt;
        private void OnPickerChanged(object sender, SelectionChangedEventArgs e)
        {
            if (ControlPicker.SelectedItem == null)
            {
                ControlApi.ItemsSource = null;
                ControlApi.Text = null;
                IntelliSenseIcon.Content = null;
                ControlApi.IsEnabled = false;
            }
            else
            {
                KeyValuePair&lt;string, Type&gt; pair = (KeyValuePair&lt;string, Type&gt;)ControlPicker.SelectedItem;
                ControlApi.ItemsSource = MemberInfoData.GetSetForType(pair.Value);
                ControlApi.IsEnabled = true;
            }
        }

        /// &lt;summary&gt;
        /// Update the visible content.
        /// &lt;/summary&gt;
        /// &lt;param name="sender"&gt;The source object.&lt;/param&gt;
        /// &lt;param name="e"&gt;The selection changed event data.&lt;/param&gt;
        private void OnApiChanged(object sender, SelectionChangedEventArgs e)
        {
            MemberInfoData mim = ControlApi.SelectedItem as MemberInfoData;
            IntelliSenseIcon.Content = ControlApi.SelectedItem == null ? null : mim.Icon;
            SelectedInformation.Text = mim == null ? string.Empty : mim.MemberInfo.Name;
        }

        /// &lt;summary&gt;
        /// Initializes the type list.
        /// &lt;/summary&gt;
        /// &lt;returns&gt;Returns a dictionary of string to Type values.&lt;/returns&gt;
        private static Dictionary&lt;string, Type&gt; InitializeTypeList()
        {
            Dictionary&lt;string, Type&gt; typeList = new Dictionary&lt;string, Type&gt;();
            Assembly[] assemblies = 
            { 
                typeof(Button).Assembly,
                typeof(TreeView).Assembly,
                typeof(AutoCompleteBox).Assembly,
                typeof(Chart).Assembly,
            };
            foreach (Assembly assembly in assemblies)
            {
                foreach (Type type in assembly.GetExportedTypes())
                {
                    if (type.IsSubclassOf(typeof(Control)))
                    {
                        typeList.Add(type.FullName, type);
                    }
                }
            }
            return typeList;
        }

        /// &lt;summary&gt;
        /// Toggle the drop down for the control, part of the custom template.
        /// &lt;/summary&gt;
        /// &lt;param name="sender"&gt;The source object.&lt;/param&gt;
        /// &lt;param name="e"&gt;The event arguments.&lt;/param&gt;
        [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Wired up in markup.")]
        private void DropDownToggle_Click(object sender, RoutedEventArgs e)
        {
            FrameworkElement fe = sender as FrameworkElement;
            AutoCompleteBox acb = null;
            while (fe != null &amp;&amp; acb == null)
            {
                fe = VisualTreeHelper.GetParent(fe) as FrameworkElement;
                acb = fe as AutoCompleteBox;
            }
            if (acb != null)
            {
                if (string.IsNullOrEmpty(acb.SearchText))
                {
                    acb.Text = string.Empty;
                }
                acb.IsDropDownOpen = !acb.IsDropDownOpen;
            }
        }
    }
}</sys:String>
    </src:SourceFile.Source>
  </src:SourceFile>
  <src:SourceFile Path="AutoCompleteComboBox.xaml.vb">
    <src:SourceFile.Source>
      <sys:String>' (c) Copyright Microsoft Corporation.
' This source is subject to the Microsoft Public License (Ms-PL).
' Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
' All other rights reserved.

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Diagnostics.CodeAnalysis
Imports System.Globalization
Imports System.Reflection
Imports System.Windows.Controls.DataVisualization.Charting
Imports System.Windows.Data
Imports System.Windows.Media

&lt;Assembly: SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields", Scope:="member", Target:="System.Windows.Controls.Samples.AutoCompleteComboBox.#ComboToggleButton", Justification:="Artifact of using a name inside the custom control template.")&gt; 

''' &lt;summary&gt;
''' The AutoCompleteComboBox sample page shows the use of custom data
''' objects, data templates, and a completely custom control template that 
''' acts and looks much like a ComboBox with AutoCompleteBox capabilities.
''' &lt;/summary&gt;
&lt;Sample("(3)Styling", DifficultyLevel.Intermediate), Category("AutoCompleteBox")&gt; _
Partial Public Class AutoCompleteComboBox
    Inherits UserControl
    ''' &lt;summary&gt;
    ''' Initializes a new instance of the AutoCompleteComboBox class.
    ''' &lt;/summary&gt;
    Public Sub New()
        InitializeComponent()
    End Sub

    ''' &lt;summary&gt;
    ''' Handle the Loaded event of the page.
    ''' &lt;/summary&gt;
    ''' &lt;param name="sender"&gt;The source object.&lt;/param&gt;
    ''' &lt;param name="rea"&gt;The event arguments.&lt;/param&gt;
    Private Sub OnLoaded(ByVal sender As Object, ByVal rea As RoutedEventArgs) Handles Me.Loaded
        ControlApi.ItemFilter = AddressOf MyItemFilter

        ' Reflect and load data
        ControlApi.ItemsSource = MemberInfoData.GetSetForType(GetType(AutoCompleteBox))
        ControlPicker.ItemsSource = InitializeTypeList()

        ' Setup the dictionary converter
        ControlPicker.ValueMemberBinding = New Binding With _
        { _
            .Converter = New DictionaryKeyValueConverter(Of String, Type)() _
        }
    End Sub

    ''' &lt;summary&gt;
    ''' AutoComplete search predicate
    ''' &lt;/summary&gt;
    ''' &lt;param name="prefix"&gt;The search string.&lt;/param&gt;
    ''' &lt;param name="item"&gt;The target object.&lt;/param&gt;
    Private Function MyItemFilter(ByVal prefix As String, ByVal item As Object) As Boolean
        If String.IsNullOrEmpty(prefix) Then
            Return True
        End If
        Dim pme As MemberInfoData = TryCast(item, MemberInfoData)
        If pme Is Nothing Then
            Return False
        End If
        Return (pme.Name.ToUpper(CultureInfo.InvariantCulture).Contains(prefix.ToUpper(CultureInfo.InvariantCulture)))
    End Function

    ''' &lt;summary&gt;
    ''' Update the API system.
    ''' &lt;/summary&gt;
    ''' &lt;param name="sender"&gt;The source object.&lt;/param&gt;
    ''' &lt;param name="e"&gt;The selection changed event data.&lt;/param&gt;
    &lt;System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification:="Event is wired up in XAML.")&gt; _
    Private Sub OnPickerChanged(ByVal sender As Object, ByVal e As SelectionChangedEventArgs)
        If ControlPicker.SelectedItem Is Nothing Then
            ControlApi.ItemsSource = Nothing
            ControlApi.Text = Nothing
            IntelliSenseIcon.Content = Nothing
            ControlApi.IsEnabled = False
        Else
            Dim pair As KeyValuePair(Of String, Type) = CType(ControlPicker.SelectedItem, KeyValuePair(Of String, Type))
            ControlApi.ItemsSource = MemberInfoData.GetSetForType(pair.Value)
            ControlApi.IsEnabled = True
        End If
    End Sub

    ''' &lt;summary&gt;
    ''' Update the visible content.
    ''' &lt;/summary&gt;
    ''' &lt;param name="sender"&gt;The source object.&lt;/param&gt;
    ''' &lt;param name="e"&gt;The selection changed event data.&lt;/param&gt;
    Private Sub OnApiChanged(ByVal sender As Object, ByVal e As SelectionChangedEventArgs) _
        Handles ControlApi.SelectionChanged, ControlPicker.SelectionChanged

        Dim mim As MemberInfoData = TryCast(ControlApi.SelectedItem, MemberInfoData)
        IntelliSenseIcon.Content = If(ControlApi.SelectedItem Is Nothing, Nothing, mim.Icon)
        SelectedInformation.Text = If(mim Is Nothing, String.Empty, mim.MemberInfo.Name)
    End Sub

    ''' &lt;summary&gt;
    ''' Initializes the type list.
    ''' &lt;/summary&gt;
    ''' &lt;returns&gt;Returns a dictionary of string to Type values.&lt;/returns&gt;
    Private Shared Function InitializeTypeList() As Dictionary(Of String, Type)
        Dim typeList As Dictionary(Of String, Type) = New Dictionary(Of String, Type)()
        Dim assemblies() As System.Reflection.Assembly = _
        { _
            GetType(Button).Assembly, _
            GetType(TreeView).Assembly, _
            GetType(AutoCompleteBox).Assembly, _
            GetType(Chart).Assembly _
        }
        For Each [assembly] As System.Reflection.Assembly In assemblies
            For Each type As Type In [assembly].GetExportedTypes()
                If type.IsSubclassOf(GetType(Control)) Then
                    typeList.Add(type.FullName, type)
                End If
            Next type
        Next [assembly]
        Return typeList
    End Function

    ''' &lt;summary&gt;
    ''' Toggle the drop down for the control, part of the custom template.
    ''' &lt;/summary&gt;
    ''' &lt;param name="sender"&gt;The source object.&lt;/param&gt;
    ''' &lt;param name="e"&gt;The event arguments.&lt;/param&gt;
    &lt;SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification:="Wired up in markup.")&gt; _
    Private Sub DropDownToggle_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
        Dim fe As FrameworkElement = TryCast(sender, FrameworkElement)
        Dim acb As AutoCompleteBox = Nothing
        While fe IsNot Nothing AndAlso acb Is Nothing
            fe = TryCast(VisualTreeHelper.GetParent(fe), FrameworkElement)
            acb = TryCast(fe, AutoCompleteBox)
        End While
        If acb IsNot Nothing Then
            If String.IsNullOrEmpty(acb.SearchText) Then
                acb.Text = String.Empty
            End If
            acb.IsDropDownOpen = Not acb.IsDropDownOpen
        End If
    End Sub

End Class

</sys:String>
    </src:SourceFile.Source>
  </src:SourceFile>
</src:SourceViewer>

    </StackPanel>
</UserControl>
